package cn.gson.springboot.controller;

import cn.gson.springboot.model.pojos.Employee;
import cn.gson.springboot.model.pojos.Solution;
import cn.gson.springboot.model.service.SolutionService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SolutionController {
    @Autowired
    SolutionService solService;
    @Autowired
    HttpSession session;

    // 查询员工需求集合
    @RequestMapping("/solution-list")
    @ResponseBody
    public Map<String,Object> allSolutionList(Integer page, Integer size,Integer vague,String content){
        Page<Object> objects = PageHelper.startPage(page, size);
        Employee emp =(Employee) session.getAttribute("emp");
        List<Solution> demands = solService.selectSolution(emp.getDepartment().getDeptId(),vague,content);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",demands);
        map.put("total",objects.getTotal());
        return map;
    }
    // 按机会Id查询员工报价集合
    @RequestMapping("/solution-opp-list")
    @ResponseBody
    public List<Solution> allSolOppIdList(Integer oppId){
        List<Solution> sol = solService.selectSolutionByOppId(oppId);
        return sol;
    }

    @RequestMapping("/save-solution")
    @ResponseBody
    public void saveQuotation(@RequestBody Solution solution){
        solService.saveSolution(solution);
    }

    @RequestMapping("/delete-solution")
    @ResponseBody
    public void deleteQuotation(@RequestParam(value = "solutionId") Integer solutionId){
        solService.deleteSolution(solutionId);
    }
}
